{% if rewrite %}
RewriteEngine On

# Make sure that CloudFront does not cache ostree summary or refs files.
# These should always be requested directly from Fedora, so any user directly
#  hitting a cloudfront setup should update their configuration.
RewriteCond %{HTTP:X-Amz-Cf-Id} !^$
RewriteRule ^/atomic/repo/summary - [F]
RewriteCond %{HTTP:X-Amz-Cf-Id} !^$
RewriteRule ^/atomic/repo/refs - [F]
RewriteCond %{HTTP:X-Amz-Cf-Id} !^$
RewriteRule ^/ostree/repo/summary - [F]
RewriteCond %{HTTP:X-Amz-Cf-Id} !^$
RewriteRule ^/ostree/repo/refs - [F]

RewriteRule ^{{remotepath}}$ %{REQUEST_URI}/ [R=301]

{% endif %}
{% if header_scheme %}
RequestHeader set X-Forwarded-Scheme https early
RequestHeader set X-Scheme https early
RequestHeader set X-Forwarded-Proto https early

{% endif %}
{% if header_expect %}
RequestHeader unset Expect early

{% endif %}
{% if keephost %}
ProxyPreserveHost On
{% endif %}


{% if datacenter == 'iad2' %}

{% if balancer_name is defined %}
<Proxy "balancer://{{balancer_name}}">
  {% for member in balancer_members %}
    BalancerMember "{{ member }}/{{remotepath}}"
  {% endfor %}
</Proxy>
ProxyPass {{ localpath }} "balancer://{{balancer_name}}"
{% else %}
ProxyPass {{ localpath }} {{ proxyurl }}{{remotepath}}
{% endif %}
ProxyPassReverse {{ localpath }} {{ proxyurl }}{{remotepath}}

{% else %}
Redirect 421 /
{% endif %}
